package cn.itenzo.common.validate;

import com.baidu.unbiz.fluentvalidator.Validator;
import com.baidu.unbiz.fluentvalidator.ValidatorContext;
import com.baidu.unbiz.fluentvalidator.ValidatorHandler;

/**
 * 至少有一个不能为空
 * @author ENZO
 */
public class LeastOneValidate extends ValidatorHandler<String[]> implements Validator<String[]>{

	
	private String title;
	
	
	
	public LeastOneValidate(String title) {
		this.title = title;
	}



	@Override
	public boolean validate(ValidatorContext context, String[] t) {
		
		boolean falg = true;
		for (String string : t) {
			if(null == string || string.trim().length()== 0)
				falg = false;
			else{
				falg = true;
				break;
			}
		}
		if(falg ){
			return true;
		}else{
			context.addErrorMsg(title + ",必须有一个不为空");
			return false;
		}
		
	}
}
